﻿using Autofac;
using Max.PH6_2006A.LowCode.IService;
using Max.PH6_2006A.LowCode.Service;

namespace Max.PH6_2006A.LowCode.API.HanldeConfig
{
    /// <summary>
    /// 自定义类，继承Autofac的模块组件
    /// </summary>
    public class AutofacConfig : Autofac.Module
    {
        /// <summary>
        /// 重写Load方法（可以F12 Autofac.Module进去复制这个方法和参数）
        /// </summary>
        /// <param name="builder"></param>
        protected override void Load(ContainerBuilder builder)
        {
            //用反射获取需要注入的程序集
            var respository =  System.Reflection.Assembly.Load("Max.PH6_2006A.LowCode.Respository");
            builder.RegisterAssemblyTypes(respository)
                .AsImplementedInterfaces()   //以接口的方式进行注入
                .InstancePerDependency(); //每次创建对象


            var service = System.Reflection.Assembly.Load("Max.PH6_2006A.LowCode.Service");
            builder.RegisterAssemblyTypes(service)
                .AsImplementedInterfaces()
                .InstancePerDependency();
                //.InstancePerRequest(); //共用同一个对象


            //builder.RegisterGeneric(typeof(BaseService<,,>)).As(typeof(IBaseService<,,>));
        }
    }
}
